package com.kgc.personconsumer.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.personcommon.pojo.Department;
import com.kgc.personcommon.pojo.Role;
import com.kgc.personconsumer.feign.DeptFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/dept")
public class DeptController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private DeptFeign deptFeign;

    @RequestMapping("getPage")
    @ResponseBody
    public ResponseMsg getPage(String pageNow, String pageSize, String name) {
        logger.info("DeptController getPage pageNow:"+pageNow+",pageSize:"+pageSize+",name:"+name);
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("pageNow",pageNow);
        map.put("pageSize",pageSize);
        ResponseMsg responseMsg =deptFeign.getDeptPage(map);
        logger.debug("deptFeign getPage responseMsg:"+responseMsg+",map:"+map);
        return responseMsg;
    }
    @RequestMapping("add")
    @ResponseBody
    public ResponseMsg addDept(@RequestBody Department department) {
        logger.info("DeptController addDept department:"+department);
        ResponseMsg responseMsg = deptFeign.addDept(department);
        logger.debug("deptFeign addRole responseMsg:"+responseMsg+",department:"+department);
        return responseMsg;
    }
    @RequestMapping("update")
    @ResponseBody
    public ResponseMsg updateDept(@RequestBody Department department) {
        logger.info("DeptController updateDept department:"+department);
        ResponseMsg responseMsg = deptFeign.updateDept(department);
        logger.debug("roleFeign updateDept responseMsg:"+responseMsg+",department:"+department);
        return responseMsg;
    }
    @RequestMapping("del")
    @ResponseBody
    public ResponseMsg del(@RequestParam("id") String id) {
        logger.info("DeptController del id:"+id);
        ResponseMsg responseMsg = deptFeign.delDept(id);
        logger.debug("deptFeign delDept responseMsg:"+responseMsg+",id:"+id);
        return responseMsg;
    }

    @RequestMapping("getById")
    @ResponseBody
    public ResponseMsg getById(@RequestParam("id") String id) {
        logger.info("DeptController getById id:"+id);
        ResponseMsg responseMsg = deptFeign.getDeptById(id);
        logger.debug("deptFeign deptFeign responseMsg:"+responseMsg+",id:"+id);
        return responseMsg;
    }

    @RequestMapping("getAll")
    @ResponseBody
    public ResponseMsg getAll() {
        logger.info("RoleController getAll role");
        Map<String,Object> map = new HashMap<>();
        ResponseMsg responseMsg = deptFeign.getAllDept(map);
        logger.debug("deptFeign getAll responseMsg:"+responseMsg+",map:"+map);
        return responseMsg;
    }
}
